import React, { PureComponent } from 'react';
import "./index.css";

export default class Parent extends PureComponent {
    state={
        carName:"长安uni-v"
    };
    changeCar=()=>{
        this.setState({
            carName:"兰博基尼"
        });
    };
    render() {
        console.log("parent-render");
        return (
            <div className="parent">
                <h3>我是Parent组件</h3>
                <span>我的车的名字叫：{this.state.carName}</span><br />
                <button onClick={this.changeCar}>点我换车</button>
                <Child carName="劳斯莱斯"></Child>
            </div>
        );
    };
};

class Child extends PureComponent {
    render(){
        console.log("child-render");
        return (
            <div className="child">
                <h3>我是child组件</h3>
                <span>我接收到的车的名字是：{this.props.carName}</span>
            </div>
        );
    };
};
